#include <tuple>

using namespace std;

template <typename T>
class Stack
{
public:
    Stack(int capacity);
    virtual ~Stack(){};
    void Clear();
    bool IsEmpty() const;
    bool IsFull() const;
    int Size() const;
    bool Push(T element);
    tuple<bool, T> Pop();

private:
    int size, top, cap;
    T *elements;
};

template <typename T>
Stack<T>::Stack(int capacity)
{
    this->size = 0;
    this->cap = capacity;
    this->elements = new T[this->cap];
    this->top = -1;
}

template <typename T>
void Stack<T>::Clear()
{
    delete this->elements;
    this->top = -1;
    this->elements = new T[this->cap];
}

template <typename T>
bool Stack<T>::IsEmpty() const
{
    return this->top == -1;
}

template <typename T>
bool Stack<T>::IsFull() const
{
    return this->Size() == this->cap;
}

template <typename T>
int Stack<T>::Size() const
{
    return this->top + 1;
}

template <typename T>
bool Stack<T>::Push(T element)
{
    if (this->IsFull())
    {
        return false;
    }
    this->elements[++this->top] = element;
    return true;
}

template <typename T>
tuple<bool, T> Stack<T>::Pop()
{
    if (this->IsEmpty())
    {
        return make_tuple(false, T());
    }
    T element = this->elements[this->top--];
    return make_tuple(true, element);
}